<div class="am-g">
    <!-- Row start -->
    <div class="am-u-sm-12">
        <div class="card-box">
            <form action="" class="am-form" data-am-validator id="doc-vld-msg">
                <fieldset>
                    <div class="am-form-group am-form-group-sm">
                        <label for="doc-vld-name-2">分类名称：</label>
                        <input type="text" name="name" class="am-form-field" id="fname" placeholder="分类名称" />
                    </div>
                    <div class="am-form-group">
                        <label class="am-u-md-2" for="doc-select-1">父级分类</label>
                        <select id="doc-select-1" name="pid">
                                <option value="0">主分类</option>
                                {{range .ol}}
                                <option value="{{.Id}}">{{.Name}}</option>
                                {{end}}
                            </select>
                        <span class="am-form-caret"></span>
                    </div>
                    <button class="am-btn am-btn-secondary" type="button">提交</button>
                </fieldset>
            </form>


        </div>
    </div>
    <!-- Row end -->
</div>
</div>
</div>
<script>
    var _url = "/sorts/add"
    $(".am-btn").on("click", function () {
        var name = $("#fname").val();
        var pid = $("#doc-select-1").val();
        console.log(pid)
        if (name.length < 1) {
            alert("分类名称不能为空！")
            return
        }
        $.post(_url, { name: name, pid: pid }, function (data) {
            if (data.status == 1) {
                alert("添加成功")
                window.location.href = data.url
            } else {
                alert(data.msg);
            }
        }, "json");
    });

</script>